package com.hibase.core.sequence.controller;

import com.github.pagehelper.PageInfo;
import com.hibase.common.constant.HibaseBaseStatus;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.sequence.entity.MdsCodeSequence;
import com.hibase.core.sequence.entity.vo.*;
import com.hibase.core.sequence.service.MdsCodeSequenceService;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import com.hibase.core.web.entity.OperationIdsEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单序列规则表 前端控制器
 * </p>
 *
 * @author jiangjy
 * @since 2019-10-15
 */
@RestController
@RequestMapping("/mds-code-sequence")
@Api(tags = "订单序列规则表")
public class MdsCodeSequenceController {

    @Autowired
    private MdsCodeSequenceService mdsCodeSequenceService;

    @ApiOperation(value = "查询订单序列规则表列表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectMdsCodeSequenceList")
    public ResponseModel<MdsCodeSequenceListVO> selectMdsCodeSequenceList(@RequestBody MdsCodeSequenceSearchVO searchVO) {

        PageInfo result = mdsCodeSequenceService.selectMdsCodeSequenceList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsCodeSequenceListVO.class));

        return ResponseModel.successMsg(result);
    }

    @ApiOperation(value = "新增订单序列规则表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "insertMdsCodeSequence")
    public ResponseModel<String> insertMdsCodeSequence(@RequestBody MdsCodeSequenceInsertVO insertVO) {

        MdsCodeSequence entity = EntityUtil.transform(insertVO, MdsCodeSequence.class);

        mdsCodeSequenceService.saveMdsCodeSequence(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "修改订单序列规则表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "updateMdsCodeSequence")
    public ResponseModel<String> updateMdsCodeSequence(@RequestBody MdsCodeSequenceUpdateVO updateVO) {

        MdsCodeSequence entity = EntityUtil.transform(updateVO, MdsCodeSequence.class);

        mdsCodeSequenceService.saveMdsCodeSequence(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "查询订单序列规则表详情", httpMethod = "POST")
    @HibasePostRequestMapping(value = "viewMdsCodeSequenceDetails")
    public ResponseModel<MdsCodeSequenceViewVO> viewMdsCodeSequenceDetails(@RequestBody OperationIdEntity operationidEntity) {

        return ResponseModel.successMsg(EntityUtil.transform(mdsCodeSequenceService.viewMdsCodeSequence(operationidEntity.getId()), MdsCodeSequenceViewVO.class));
    }

    @ApiOperation(value = "删除订单序列规则表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/deleteMdsCodeSequence")
    public ResponseModel<String> deleteMdsCodeSequence(@RequestBody OperationIdEntity delete) {

        mdsCodeSequenceService.deleteMdsCodeSequence(delete.getId());

        return ResponseModel.successMsg();
    }

    @ApiOperation(value = "启用订单序列规则", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/enableMdsCodeSequence")
    public ResponseModel<String> enableMdsCodeSequence(@RequestBody OperationIdsEntity enable) {

        mdsCodeSequenceService.changeMdsCodeSequence(enable.getIds(), HibaseBaseStatus.ENABLE.getKey());

        return ResponseModel.successMsg();
    }

    @ApiOperation(value = "禁用订单序列规则", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/disabledMdsCodeSequence")
    public ResponseModel<String> disabledMdsCodeSequence(@RequestBody OperationIdsEntity disabled) {

        mdsCodeSequenceService.changeMdsCodeSequence(disabled.getIds(), HibaseBaseStatus.DISABLE.getKey());

        return ResponseModel.successMsg();
    }
}
